package com.huisheng.com.huisheng.dao;

import com.huisheng.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

/**
 * @Authther: mrwu
 * @date:2021/3/5-03
 * @Description:com.huisheng.com.huisheng.dao
 */
public class UserDaoImpl implements UserDao{
    @Override
    public List<User> findAll() throws Exception{

        InputStream input = Resources.getResourceAsStream("sqlMapConfigration.xml");
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(input);
        SqlSession sqlSession = sessionFactory.openSession();
        List<User> users = sqlSession.selectList("user.findAll");
//        for (User user:users
//        ) {
//            System.out.println(user);
//        }
        sqlSession.close();
        return users;
    }
}
